//
//  Collection_List_Cell.m
//  LoveTravel
//
//  Created by MS on 16-1-23.
//  Copyright (c) 2016年 Lemon. All rights reserved.
//

#import "Collection_List_Cell.h"
#import "List_ItemView.h"
#import "UIImageView+WebCache.h"

@interface Collection_List_Cell ()
@property (weak, nonatomic) IBOutlet UIView *conView;
@property (weak, nonatomic) IBOutlet UIView *conTextView;
@property (weak, nonatomic) IBOutlet UILabel *textView;
@property (nonatomic,weak) List_ItemView * itemView;

@end

@implementation Collection_List_Cell


-(void)setRecommData:(RecommsData *)recommData
{
    _recommData = recommData;
    [_itemView.bgImageView sd_setImageWithURL:[NSURL URLWithString:recommData.bg_pic[0]]];
    _itemView.titleView.text = recommData.title;
    _itemView.subTitleView.text = recommData.sub_title;
    _itemView.locationTitleView.text = recommData.destination;
    
    NSString * startTime = [self stringComponentWithString:recommData.start_date];
    NSString * endTime = [self stringComponentWithString:recommData.end_date];
    
    _itemView.titmeTitleView.text = [NSString stringWithFormat:@"%@--%@",startTime,endTime];
    
    _textView.text = recommData.short_desc;

}


-(NSString *)stringComponentWithString:(NSString *)str
{
    NSArray * strArray = [str componentsSeparatedByString:@"-"];
    
    NSMutableString * dataStr = [NSMutableString string];
    int i =0;
    for (NSString * str in strArray) {
        
        NSString * newstr = nil;
        if ([str hasPrefix:@"0"]) {
            newstr = [str substringFromIndex:1];
        }else{
            newstr = str;
        }
        
        if (i==1) {
            newstr = [NSString stringWithFormat:@"%@月",newstr];
            [dataStr appendString:newstr];
        }
        if (i==2) {
            newstr = [NSString stringWithFormat:@"%@日",newstr];
            [dataStr appendString:newstr];
        }
        
        i++;
    }

    return dataStr;
}


-(void)awakeFromNib
{
    List_ItemView * view = [List_ItemView list_ItemViewWithXib];
    view.frame = self.conView.bounds;
    [_conView addSubview:view];
    self.itemView = view;
    
    _conTextView.backgroundColor = [UIColor colorWithRed:0.97f green:0.97f blue:0.97f alpha:1.00f];
}

@end
